////////////////////////////////////////////////
// File: SyscityService.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:33
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.service;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mvc.dao.EntityDao;
import com.mvc.entity.Syscity;
import com.mvc.entity.Sysprovince;
import com.pub.Page;

@Service
public class  SyscityService {
	@Autowired
	private EntityDao entityDao;

	@Transactional
	public List<Object> getSyscityList(String hql, Page page) {
		List<Object> list = entityDao.pageQuery(hql, page.getPageNo(),
				page.getPageSize());
		return list;
	}

	public int getCount(String hql, Page page) {
		int count = 0;
		count = entityDao.countQuery(hql);
		if ((count % page.getPageSize()) == 0) {
			count = count / page.getPageSize();
		}else
		{
			count = count / page.getPageSize() + 1;
		}
		return count;
	}

	public void Save( Syscity  syscity) {
		entityDao.save(syscity);
	}

	public void EditSave(Syscity syscity) {
		entityDao.saveOrUpdate(syscity);
	}

	public void Del(String ID) {
		entityDao.delById(Syscity.class, Integer.parseInt(ID));
	}

	public Syscity getSyscityByHql(String hql) {
		Syscity syscity = (Syscity) entityDao.loadObject(hql);
		return syscity;
	}
    
   public Syscity getSyscity(String ID){
	   Syscity syscity=(Syscity) entityDao.loadById(Syscity.class,Integer.valueOf(ID));
	   return syscity;
      }
	public List<Object> getListByHql(String hql) {
		List<Object> list = entityDao.query(hql);
		return list;
	}
	   public Sysprovince getProvince(String Pname){
		   String hql="select a from Sysprovince a where a.Pname='"+Pname+"'";
		   Sysprovince sysprovince = (Sysprovince) entityDao.loadObject(hql);
		   return sysprovince;
	      }
	   
	   public Syscity getCity(String City){
		   String hql="select a from Syscity a where a.Cname='"+City+"'";
		   Syscity syscity = (Syscity) entityDao.loadObject(hql);
		   return syscity;
	      }
		public List<Object> getCityList(String Pname) {
			Sysprovince sp=getProvince(Pname);
			String hql="select a from Syscity a where a.Provicecode='"+sp.getPcode()+"'";;
			List<Object> list = entityDao.query(hql);
			return list;
		}
}
